1466A - Bovine Dilemma - CodeForces Solution


brute force geometry math *800

Please click on ads to support us..

Python Code:

for _ in range(int(input())):
    n = int(input())
    w = [int(i) for i in input().split()]
    a = []
    for i in range(n-1):
        for j in range(n-i-1):
            if w[j+1+i] - w[j] not in a:
                a.append(w[j+i+1]-w[j])
    print(len(a))

C++ Code:

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef complex<double> P;

#define pi 3.1415926
#define todegree(c) c*180.0/pi
#define torad(c) c*pi/180
#define X real()
#define Y imag()

const double eps = 1e-9;


int main()
{

    ll t;
    cin>>t;
    while(t--)
        {
            ll n;
            cin>>n;
            vector<double> v;
            for(int i=0;i<n;i++)
                {
                    double temp;
                    cin>>temp;
                    v.push_back(temp);
                }

            P tree= {0.0,1.0};
            map<ll,bool> mp;
            ll ans=0;
            for(int i=0;i<n;i++)
                {
                    for(int j=i+1;j<n;j++)
                        {
                   //         cout<<v[i]<<" "<<v[j]<<" ";
                            P point1 = {v[i],0};
                            P point2 = {v[j],0};
                            double a = abs(tree-point1);
                            double b = abs(tree-point2);
                            double c = abs(point1-point2);
                            double s = (a+b+c)/2;
                            double area = (s*(s-a)*(s-b)*(s-c));
                            area = sqrt(area);
                            area = round(area*10000);

                     //       cout<<area<<endl;
                            if(!mp[(int)area]){ans++;mp[(int)area]=1;}
                        }
                }
            cout<<ans<<endl;
        }


    return 0;
}


Comments

Submit
0 Comments
More Questions

1143B - Nirvana
1285A - Mezo Playing Zoma
919B - Perfect Number
894A - QAQ
1551A - Polycarp and Coins
313A - Ilya and Bank Account
1469A - Regular Bracket Sequence
919C - Seat Arrangements
1634A - Reverse and Concatenate
1619C - Wrong Addition
1437A - Marketing Scheme
1473B - String LCM
1374A - Required Remainder
1265E - Beautiful Mirrors
1296A - Array with Odd Sum
1385A - Three Pairwise Maximums
911A - Nearest Minimums
102B - Sum of Digits
707A - Brain's Photos
1331B - Limericks
305B - Continued Fractions
1165B - Polycarp Training
1646C - Factorials and Powers of Two
596A - Wilbur and Swimming Pool
1462B - Last Year's Substring
1608B - Build the Permutation
1505A - Is it rated - 2
169A - Chores
765A - Neverending competitions
1303A - Erasing Zeroes